package com.qdlc.p2p.biz.service.activity.plan;

import java.util.Map;

import org.springframework.stereotype.Service;

import com.qdlc.p2p.biz.service.activity.AbstractActivityPlanHandler;
import com.qdlc.p2p.biz.service.activity.ActivityPlanEnum;
import com.qdlc.p2p.biz.service.activity.ActivityPlanException;
import com.qdlc.p2p.biz.service.activity.ActivityPlanParam;
import com.qdlc.p2p.biz.service.activity.ActivityProgrammeEnum;
import com.qdlc.p2p.biz.service.activity.ActivityProgrammeHandler;
import com.qdlc.p2p.biz.service.activity.ActivityProgrammeParam;

/**
 * 自定义活动环节
 * @author linya
 */
@Service
public class CustomActivityPlanHandler extends AbstractActivityPlanHandler{

	/**
	 * 执行活动
	 * @param planEnum
	 * @param param
	 * @throws ActivityPlanException 
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public void doPlan(ActivityPlanParam planParam) throws ActivityPlanException {
		
		//获取参数
		Map<ActivityProgrammeEnum, ActivityProgrammeParam> programmeParamMaps = planParam.getAllProgrammeParams();
		if(programmeParamMaps.size() == 0){
			return;
		}
		
		ActivityPlanEnum planEnum = planParam.getActivityPlan();
		if(planEnum == null){
			throw new ActivityPlanException("++++ please set a ActivityPlanEnum for ActivityPlanParam");
		}
		
		//执行活动方案
		for(Map.Entry<ActivityProgrammeEnum, ActivityProgrammeParam> entry: programmeParamMaps.entrySet()){
			ActivityProgrammeEnum programmeEnum = entry.getKey();
			ActivityProgrammeParam programmeParam = entry.getValue();
			programmeParam.setActivityPlan(planEnum);
			programmeParam.setUser(planParam.getUser());
			ActivityProgrammeHandler handler = activityProgrammeMap.get(programmeEnum);
			handler.handleCustom(programmeParam);
		}
		
	}
	
}
